package com.mydesign.demo.config;

import com.mydesign.demo.Handler.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyWebMvc implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
                .addPathPatterns("/store/StoreList")//添加需要拦截的接口
        .excludePathPatterns("/user/**")//添加释放的接口
        ;
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        System.err.println("获取到的操作系统是："+os);
        //如果是Windows系统
        if (os.toLowerCase().startsWith("win")) {
            registry.addResourceHandler("/img/**")
                    // /apple/**表示在磁盘apple目录下的所有资源会被解析为以下的路径
                    .addResourceLocations("file:D:/mydesign/video/");;  //swagger2页面
        } else {
            //linux 和mac  .addResourceLocations("classpath:/META-INF/resources/");  //swagger2页面;
            registry.addResourceHandler("/img/**")
                    .addResourceLocations("file:/mydesign/video/");   //媒体资源

        }
    }
}
